class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


# 改值
# class Solution(object):
#     def hasCycle(self, head):
#         """
#         :type head: ListNode
#         :rtype: bool
#         """
#         if not head:
#             return False
#         value = 2 * 10 ** 5 + 1
#         max_value = 10 ** 5
#         node = head
#         while node:
#             if node.val > max_value:
#                 return True
#             else:
#                 node.val += value
#                 node = node.next
#         return False

# 快慢指针

class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head:
            return False
        node = ListNode(0)
        node.next = head
        slow = node
        fast = node.next
        while fast:
            fast = fast.next
            if fast:
                fast = fast.next
            else:
                return False
            slow = slow.next
            if fast == slow:
                return True
